from Monitor.NetworkMonitor import NetworkDelayMonitor,NetworkMonitor,MonitorType,NetworkBandWidthMonitor
from containernet.node import DockerSta
from OSM_Mininet_wifi.node import OSMDockerStaion,OSMDockerCloud
from containernet.cli import CLI
from containernet.term import makeTerm
from mininet.log import info, setLogLevel,output
from mn_wifi.mobility import Mobility
from mininet.node import Controller
from OSM_Mininet_wifi.net import OSM_Mininet_wifi
from mn_wifi.net import OVSKernelAP

setLogLevel('info')
net = OSM_Mininet_wifi(controller=Controller,autoAssociation=False)


net.addAccessPoint(**{'type': 'bs', 'name': 'bs0', 'location': [28.230216766637962, 112.97197866446369], 'position': [-95, 328, 0], 'ssid': 'ssid-bs0', 'ip': '10.0.0.1/8', 'ip6': '2001:0:0:0:0:0:0:1/64', 'mac': '00:00:00:00:00:01', 'range': 500, 'failMode': 'standalone'})
net.addAccessPoint(**{'type': 'bs', 'name': 'bs1', 'location': [28.22806586891457, 112.97940731048584], 'position': [633, 88, 0], 'ssid': 'ssid-bs1', 'ip': '10.0.0.2/8', 'ip6': '2001:0:0:0:0:0:0:2/64', 'mac': '00:00:00:00:00:02', 'range': 500, 'failMode': 'standalone'})
net.addStation(**{'type': 'mp', 'name': 'mp0', 'location': ['28.226531821986317,112.9807333946883', '28.23012228246697,112.97324466711873'], 'position': '763,-82,0', 'ip': '10.0.0.3/8', 'ip6': '2001:0:0:0:0:0:0:3/64', 'mac': '00:00:00:00:00:03', 'range': 500, 'speed': 50, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerStaion)
net.OSM_Mobility_For_ConfigurationData(**{'NodeMobilityConfig': {'speed': 50, 'coord': ['838,-74,0', '576,-69,0', '418,-62,0', '410,-62,0', '162,-58,0', '99,-56,0', '85,-56,0', '45,-55,0', '-94,-42,0', '-323,-21,0', '-316,21,0', '-307,82,0', '-302,111,0', '-301,118,0', '-262,128,0', '-226,154,0', '-203,175,0', '-164,205,0', '-142,225,0', '-93,269,0', '-78,283,0', '-45,308,0', '-36,312,0', '-29,313,0'], 'distance': 1642.9864371879644}, 'node': 'mp0'})
net.addDocker(**{'type': 'ec', 'name': 'ec0', 'location': [28.228383758791107, 112.98131275183553], 'position': [819, 124, 0], 'ip': '10.0.0.4/8', 'ip6': '2001:0:0:0:0:0:0:4/64', 'mac': '00:00:00:00:00:04', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.addDocker(**{'type': 'ec', 'name': 'ec1', 'location': [28.23150174305852, 112.97161388403767], 'position': [-131, 470, 0], 'ip': '10.0.0.5/8', 'ip6': '2001:0:0:0:0:0:0:5/64', 'mac': '00:00:00:00:00:05', 'range': 500, 'dimage': 'ubuntu:test2', 'sysctls': {'net.ipv6.conf.all.disable_ipv6': '0'}},cls=OSMDockerCloud)
net.startController(**{'controller': 'None', 'name': 'c', 'number': 1, 'ip': '127.0.0.1', 'port': 6653, 'protocol': 'tcp', 'app': 'simple_switch'})
net.configureWifiNodes()
net.addLink(**{'type': 'nl', 'node1': 'bs1', 'node2': 'ec0', 'delay': '0ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.addLink(**{'type': 'nl', 'node1': 'bs0', 'node2': 'ec1', 'delay': '0ms', 'bw': 10, 'jitter': '0ms', 'loss': 0})
net.OSM_Mobility_Setting(**{'mobility_start_time': 1, 'reverse': 1, 'ac_method': 'ssf', 'mob_rep': 1, 'mobility_mode': 'quickly'})
net.start()
thread_list = []
t=NetworkBandWidthMonitor('mp0', 'ec0', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530221858378670.json',**{'period': 60}).thread_
thread_list.append(t)
t=NetworkBandWidthMonitor('mp0', 'ec1', net, monitor_type= {'band_width'}).start(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530221858378670.json',**{'period': 60}).thread_
thread_list.append(t)
for td in thread_list: td.join()
net.OSM_Experiment_Ended(data_storage_Directory='/home/kylin/Desktop/PythonProject/OSM_Mininet_WIFI/Mininet_WIFI/Network_Topology/Network_Topology_20230530221858378670.json')
net.stop()
